home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLOBSH.PAK / LTIME.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  188 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  LTIME.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __LTIME_H )
  11. #define __LTIME_H
  12.  
  13. #define BI_OLDNAMES
  14.  
  15. #if !defined( __DOS_H )
  16. #include <Dos.h>
  17. #endif  // __DOS_H
  18.  
  19. #if !defined( __CHECKS_H )
  20. #include <checks.h>
  21. #endif  // __CHECKS_H
  22.  
  23. #if !defined( __SORTABLE_H )
  24. #include "classlib\obsolete\Sortable.h"
  25. #endif  // __SORTABLE_H
  26.  
  27. #pragma option -Vo-
  28. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  29. #pragma option -po-
  30. #endif
  31.  
  32. _CLASSDEF(ostream)
  33. _CLASSDEF(BaseTime)
  34. _CLASSDEF(Time)
  35.  
  36. class _CLASSTYPE BaseTime : public Sortable
  37. {
  38.  
  39. public:
  40.  
  41.     unsigned hour() const;
  42.     unsigned minute() const;
  43.     unsigned second() const;
  44.     unsigned hundredths() const;
  45.     void setHour( unsigned _TCHAR );
  46.     void setMinute( unsigned _TCHAR );
  47.     void setSecond( unsigned _TCHAR );
  48.     void setHundredths( unsigned _TCHAR );
  49.  
  50.     virtual classType isA() const = 0;
  51.     virtual _TCHAR _FAR *nameOf() const = 0;
  52.     virtual hashValueType hashValue() const;
  53.     virtual int isEqual( const Object _FAR & ) const;
  54.     virtual int isLessThan( const Object _FAR & ) const;
  55.     virtual void printOn( ostream _FAR & ) const = 0;
  56.  
  57. protected:
  58.  
  59.     BaseTime();
  60.     BaseTime( const BaseTime _FAR & );
  61.     BaseTime( unsigned _TCHAR,
  62.               unsigned _TCHAR = 0,
  63.               unsigned _TCHAR = 0,
  64.               unsigned _TCHAR = 0
  65.             );
  66.  
  67. private:
  68.  
  69.     unsigned _TCHAR HH;
  70.     unsigned _TCHAR MM;
  71.     unsigned _TCHAR SS;
  72.     unsigned _TCHAR HD;
  73. };
  74.  
  75. inline BaseTime::BaseTime()
  76. {
  77.     struct time t;
  78.     gettime( &t );
  79.     HH = t.ti_hour;
  80.     MM = t.ti_min;
  81.     SS = t.ti_sec;
  82.     HD = t.ti_hund;
  83. }
  84.  
  85. inline BaseTime::BaseTime( const BaseTime _FAR & B ) :
  86.     HH(B.HH), MM(B.MM), SS(B.SS), HD(B.HD)
  87. {
  88. }
  89.  
  90. inline BaseTime::BaseTime( unsigned _TCHAR H, unsigned _TCHAR M, unsigned _TCHAR S, unsigned _TCHAR D )
  91. {
  92.     setHour( H );
  93.     setMinute( M );
  94.     setSecond( S );
  95.     setHundredths( D );
  96. }
  97.  
  98. inline unsigned BaseTime::hour() const
  99. {
  100.     return HH;
  101. }
  102.  
  103. inline unsigned BaseTime::minute() const
  104. {
  105.     return MM;
  106. }
  107.  
  108. inline unsigned BaseTime::second() const
  109. {
  110.     return SS;
  111. }
  112.  
  113. inline unsigned BaseTime::hundredths() const
  114. {
  115.     return HD;
  116. }
  117.  
  118. inline void BaseTime::setHour( unsigned _TCHAR anHour )
  119. {
  120.     PRECONDITION( anHour < 24 );
  121.     HH = anHour;
  122. }
  123.  
  124. inline void BaseTime::setMinute( unsigned _TCHAR M )
  125. {
  126.     PRECONDITION( M < 60 );
  127.     MM = M;
  128. }
  129.  
  130. inline void BaseTime::setSecond( unsigned _TCHAR S )
  131. {
  132.     PRECONDITION( S < 60 );
  133.     SS = S;
  134. }
  135.  
  136. inline void BaseTime::setHundredths( unsigned _TCHAR D )
  137. {
  138.     PRECONDITION( D < 100 );
  139.     HD = D;
  140. }
  141.  
  142. class _CLASSTYPE Time : public BaseTime
  143. {
  144.  
  145. public:
  146.  
  147.     Time();
  148.     Time( const Time _FAR & );
  149.     Time( unsigned _TCHAR,
  150.           unsigned _TCHAR = 0,
  151.           unsigned _TCHAR = 0,
  152.           unsigned _TCHAR = 0
  153.         );
  154.  
  155.     virtual classType isA() const
  156.         {
  157.         return timeClass;
  158.         }
  159.  
  160.     virtual _TCHAR _FAR *nameOf() const
  161.         {
  162.         return "Time";
  163.         }
  164.  
  165.     virtual void printOn( ostream _FAR & ) const;
  166. };
  167.  
  168. inline Time::Time() : BaseTime()
  169. {
  170. }
  171.  
  172. inline Time::Time( const Time& T ) : BaseTime( T )
  173. {
  174. }
  175.  
  176. inline Time::Time( unsigned _TCHAR H, unsigned _TCHAR M, unsigned _TCHAR S,
  177.                    unsigned _TCHAR D ) :  BaseTime( H, M, S, D )
  178. {
  179. }
  180.  
  181. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  182. #pragma option -po.
  183. #endif
  184. #pragma option -Vo.
  185.  
  186. #endif  // __LTIME_H
  187.  
  188.